package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.ApplysheetDev;
import com.ruoyi.huanghefd.service.ApplysheetDevService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author gnplum
 * @Date 2023/11/13 0:58
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: ApplysheetDevController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class ApplysheetDevController {
    private static final Logger log = LoggerFactory.getLogger(ApplysheetDevController.class);

    @Resource
    private ApplysheetDevService applysheetDevService;

    /**
     * @Author gnplum
     * @Description //新增 检修设备试运行、恢复运行申请单
     * @Date 9:48 2023/11/13
     * @param applysheetDev
     * @return com.ruoyi.huanghefd.domain.ResultWS
     **/
    @PostMapping("/addApplysheetDEV")
    public AjaxResult addApplysheetDEV(@RequestBody ApplysheetDev applysheetDev){
        log.info(">> 新增检修设备试运行、恢复运行申请单-入参==" + JSON.toJSONString(applysheetDev));
        AjaxResult ajax = applysheetDevService.addApplysheetDev(applysheetDev);
        log.info("<< 新增检修设备试运行、恢复运行申请单-返回==" + ajax.toString());
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //删除 检修设备试运行、恢复运行申请单
     * @Date 15:22 2023/10/31
     * @param apCode
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @PostMapping(value = "/delApplysheetDEV")
    public AjaxResult delApplysheetDEV(@RequestParam(required = false,value = "apCode") String apCode){
        log.info(">> 删除检修设备试运行、恢复运行申请单-入参 apCode==" + apCode);
        if(apCode.isEmpty()){
            return AjaxResult.success("请点选要删除的检修设备试运行、恢复运行申请单");
        }
        AjaxResult ajax = applysheetDevService.delApplysheetDev(apCode);
        log.info(">> 删除检修设备试运行、恢复运行申请单-返回==" + ajax);
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //修改 检修设备试运行、恢复运行申请单
     * @Date 15:47 2023/10/31
     * @param applysheetDev
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:8080/huanghefd/uptWorksheet
     **/
    @PostMapping(value = "/uptApplysheetDEV")
    public AjaxResult uptApplysheetDEV(@RequestBody ApplysheetDev applysheetDev){
        log.info(">> 修改检修设备试运行、恢复运行申请单入参 ==" + JSON.toJSONString(applysheetDev));
        AjaxResult ajax = applysheetDevService.uptApplysheetDev(applysheetDev);
        log.info(">> 修改检修设备试运行、恢复运行申请单-返回 ==" + ajax);
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //查询 检修设备试运行、恢复运行申请单
     * @Date 9:48 2023/10/31
     * @param apCode,apState
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:18080/huanghefd/queryWorksheet?wsCode=20231102000001&wsDept=100
     **/
    @PostMapping(value = "/queryApplysheetDEV")
    public AjaxResult queryApplysheetDEV(@RequestParam(required = false,value = "apCode") String apCode,@RequestParam(required = false,value = "apDept") String apDept,@RequestParam(required = false,value = "apState") String apState,@RequestParam(required = false,value = "userId") String userId,@RequestParam(required = false,value = "mailType") String mailType){
        log.info(">> 查询检修设备试运行、恢复运行申请单-入参==" + apCode + "," + "," + apDept + "," + apState + "," + userId + "," + mailType);
        AjaxResult ajax= applysheetDevService.queryApplysheetDevs(apCode,apDept,apState,userId,mailType);//mailType 1-收件箱 2-发件箱
        log.info(">> 查询检修设备试运行、恢复运行申请单-返回==" + ajax);
        return ajax;
    }
    @PostMapping(value = "/queryApplysheetDEV1")
    public PageBean queryApplysheetDEV(@RequestParam(required = false,value = "apCode") String apCode, @RequestParam(required = false,value = "apDept") String apDept, @RequestParam(required = false,value = "apState") String apState, @RequestParam(required = false,value = "userId") String userId, @RequestParam(required = false,value = "mailType") String mailType, @RequestParam(value = "pageNum") int pageNum, @RequestParam(value = "pageSize") int pageSize){
        log.info(">> 查询检修设备试运行、恢复运行申请单-入参==" + apCode + "," + "," + apDept + "," + apState + "," + userId + "," + mailType);
        PageBean ajax = applysheetDevService.queryApplysheetDevsByPage(apCode, apDept, apState, userId, mailType, pageNum, pageSize);//mailType 1-收件箱 2-发件箱
        log.info(">> 查询检修设备试运行、恢复运行申请单-返回==" + ajax);
        return ajax;
    }
}
